package org.itboys.core.util;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import lombok.extern.log4j.Log4j;
import lombok.extern.log4j.Log4j2;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.commons.httpclient.methods.RequestEntity;
import org.apache.commons.httpclient.methods.StringRequestEntity;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;
import org.itboys.commons.CommonConstants;
import org.itboys.commons.utils.time.TimeUtils;
import org.itboys.commons.utils.tools.ListUtil;
import org.itboys.core.common.SundayCommonConstants;
import org.itboys.core.entity.mongo.SundayCartGoodsSize;
import org.itboys.core.entity.mysql.SundayOrder;
import org.itboys.param.ParamUtil;
import org.omg.PortableInterceptor.INACTIVE;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.math.BigDecimal;
import java.util.*;

import static org.itboys.core.util.JsonUtil.map2Json;


/**
 * 包名：com.hz.sunday.chint.utils
 * 作者 : 江雄
 * Email: empty90911@126.com
 * 时间：2015年9月23日 下午2:05:43
 * 描述:修改，返回距离单位，公里
 */
@Slf4j
public class TestUtils {

    public static void main(String[] args) throws IOException {

        System.out.println(TimeUtils.formatToTime(new Date(1528792146147l)));
      /*  JSONObject paramJson = new JSONObject();
        paramJson.put("orderNo", "xxsadfsdf");
        JSONObject object = JNBYRequestUtil.request(paramJson, "108d1f62b2e7f5a755230479f5eff13d", SundayCommonConstants.order_find_url);
        JSONObject data = (JSONObject) object.get("data");
        System.out.println(data!=null);*/


      /*  JSONObject paramJson = new JSONObject();

        paramJson.put("c_vip_id", "7998923");
        paramJson.put("sourceCode", "HOME2018112019109105");
        paramJson.put("description","由HOME小程序传入网店订单生成！");
        paramJson.put("receiver_name", "哥哥");
        paramJson.put("c_province_id", "3");
        paramJson.put("c_city_id", "12");
        paramJson.put("c_district_id", "894");
        paramJson.put("receiver_address","安阳县中医医院");
        paramJson.put("receiver_mobile", "13838000000");
        paramJson.put("source", "MART");
        paramJson.put("outcode", "104");
        List<JSONObject> productItem=new ArrayList<>();

        JSONObject codeSize1=new JSONObject();
        codeSize1.put("id", "593159");
        codeSize1.put("codeId", "1231806");
        codeSize1.put("qty", "1");
        codeSize1.put("priceactual", "220");
        productItem.add(codeSize1);

    *//*    JSONObject codeSize2=new JSONObject();
        codeSize2.put("id", "592923");
        codeSize2.put("codeId", "1232015");
        codeSize2.put("qty", "1");
        codeSize2.put("priceactual", "190");
        productItem.add(codeSize2);*//*

        paramJson.put("productItem", productItem);
        List<JSONObject> payitem=new ArrayList<>();
        JSONObject wxPay1=new JSONObject();
        wxPay1.put("c_payway_id", "62");
        wxPay1.put("payamount", "220");

        payitem.add(wxPay1);
        paramJson.put("payitem", payitem);
        log.info("江南布衣创建订单请求参数 = {}", paramJson.toJSONString());
        JSONObject requestResult =JNBYRequestUtil.request(paramJson, "108d1f62b2e7f5a755230479f5eff13d", SundayCommonConstants.order_add_url);
        log.info("江南布衣创建订单请求结果"+requestResult.toJSONString());
        JSONObject data= (JSONObject) requestResult.get("data");
        Integer ret=data.getIntValue("ret");*/
        List<String> codeList = new ArrayList<>();
        codeList.add("HH81IA25038104");
        codeList.add("HH300402141503");
        JSONObject paramJson = new JSONObject();
        paramJson.put("ids", codeList);
        JSONObject jsonResult = JNBYRequestUtil.request(paramJson, "108d1f62b2e7f5a755230479f5eff13d", SundayCommonConstants.goods_store_url);
        List<JSONObject> responseData = (List<JSONObject>) jsonResult.get("data");
        if (ListUtil.isNotNull(responseData)) {
                for (JSONObject object : responseData) {
                    String objectCode=object.getString("code");
                    System.out.println(objectCode);
                    Integer objectKcsl=object.getIntValue("kcsl");


                }

        }

    }
    public static String toUTF8(String str) {
        if (isEmpty(str)) {
            return "";
        }
        try {
            if (str.equals(new String(str.getBytes("GB2312"), "GB2312"))) {
                str = new String(str.getBytes("GB2312"), "utf-8");
                return str;
            }
        } catch (Exception exception) {
        }
        try {
            if (str.equals(new String(str.getBytes("ISO-8859-1"), "ISO-8859-1"))) {
                str = new String(str.getBytes("ISO-8859-1"), "utf-8");
                return str;
            }
        } catch (Exception exception1) {
        }
        try {
            if (str.equals(new String(str.getBytes("GBK"), "GBK"))) {
                str = new String(str.getBytes("GBK"), "utf-8");
                return str;
            }
        } catch (Exception exception3) {
        }
        return str;
    }

    public static boolean isEmpty(String str) {
        // 如果字符串不为null，去除空格后值不与空字符串相等的话，证明字符串有实质性的内容
        if (str != null && !str.trim().isEmpty()) {
            return false;// 不为空
        }
        return true;// 为空
    }
}
